<?php
namespace app\adminapiv3\controller;

use app\adminapiv3\service;
class Email extends Base
{
    /**
     * @name: 详情
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-08-14 16:37:45
     */
    function info ()
    {
        $Email = new service\Email();
        $data = $Email->info();

        self::jsonOutPut($data);
    }

    /**
     * @name: 修改
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-08-14 16:38:09
     */
    function modify ()
    {
        global $logContent;
        $logContent = '修改预警配置';

        //接收参数
        $data['smtp_addr'] = $this->filterInput('smtp_addr*','post');//stmp地址
        $data['smtp_port'] = $this->filterInput('smtp_port*','post');//stmp端口
        $data['username'] = $this->filterInput('username*','post');//用户名
        $data['password'] = $this->filterInput('password*','post');//密码
        $data['email_addr'] = $this->filterInput('email_addr*','post');//发件箱地址

        $Email = new service\Email();
        $Email->modify($data);



        self::jsonOutPut();
    }

    /**
     * @name 异步发送 邮件
     * @author wx
     * @date 2020/8/28 9:15
     */
    function send(){

        $title = input('title');
        $content = input('send_content');

        $logFile = '../runtime/email.log';

        //记录日志
        if (file_exists($logFile) && filesize($logFile) >= 5 * 1024 * 1024 * 1024) {
            unlink($logFile);
        }

        file_put_contents($logFile, date('Y-m-d H:i:s').$title.$content.PHP_EOL, FILE_APPEND);

        $Email = new service\Email();
        $res = $Email->sendEmail($title, $content);

        if($res){
            file_put_contents($logFile, 'success'.PHP_EOL, FILE_APPEND);
        }else{
            file_put_contents($logFile, 'fail'.PHP_EOL, FILE_APPEND);
        }


    }
    
}